package com.junci.mtest.model.bean;

import android.os.Parcel;
import android.os.Parcelable;


/**
 * 尼莫
 * 这是~
 */
public class ErrorMessage implements Parcelable {

    public static final int NETWORK_ERROR = 333;

    public String message() {
        return message;
    }

    public int code() {
        return code;
    }

    public String getResultCode() {
        return resultCode;
    }

    public void setResultCode(String resultCode) {
        this.resultCode = resultCode;
    }

    public String other() {
        return other;
    }

    public ErrorMessage(String message, int code, String other) {
        this.message = message;
        this.code = code;
        this.other = other;
    }

    public ErrorMessage(String message, String resultCode) {
        this.message = message;
        this.resultCode = resultCode;
    }

    private String message = "";
    private int code;
    private String resultCode = "";
    private String other      = "";


    public static ErrorMessage create(String message, int code, String other) {
        return new ErrorMessage(message, code, other);
    }

    public static ErrorMessage create(String message, int code) {
        return new ErrorMessage(message, code, "");
    }

    public static ErrorMessage create(String message, String resultCode) {
        return new ErrorMessage(message, resultCode);
    }

    public static ErrorMessage create(String message) {
        return new ErrorMessage(message, 1, "");
    }

    public static ErrorMessage createByNotNetwork(Exception e) {
        return new ErrorMessage("网络不给力，请检查网络或稍后重试", NETWORK_ERROR, e.getMessage());
    }

    public static ErrorMessage createByReqError(Throwable e) {
        // 一般情况是json解析失败了 或者是服务器出错了 反正一句话 就是服务器的事  这锅 我们客户端不背！ 500 502 404 等等等等

        return new ErrorMessage("网络不给力，请检查网络或稍后重试", 1, e.getMessage());
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.message);
        dest.writeInt(this.code);
        dest.writeString(this.other);
        dest.writeString(this.resultCode);
    }

    public ErrorMessage() {
    }

    protected ErrorMessage(Parcel in) {
        this.message = in.readString();
        this.code = in.readInt();
        this.other = in.readString();
        this.resultCode = in.readString();
    }

    public static final Creator<ErrorMessage> CREATOR = new Creator<ErrorMessage>() {
        @Override
        public ErrorMessage createFromParcel(Parcel source) {
            return new ErrorMessage(source);
        }

        @Override
        public ErrorMessage[] newArray(int size) {
            return new ErrorMessage[size];
        }
    };

    @Override
    public String toString() {
        return "ErrorMessage{" +
                "message='" + message + '\'' +
                ", code=" + code +
                ", resultCode='" + resultCode + '\'' +
                ", other='" + other + '\'' +
                '}';
    }
}
